<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【添加订单】列表')" />
    <script src="../../..   /js/jquery.min.js"></script>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单id：</label>
                                <input type="text" name="id"/>
                            </li>
<!--                            <li>-->
<!--                                <label>寄件省：</label>-->
<!--                                <input type="text" name="sendProvince"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件市：</label>-->
<!--                                <input type="text" name="sendCity"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件区：</label>-->
<!--                                <input type="text" name="sendCounty"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件街道：</label>-->
<!--                                <input type="text" name="sendTown"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件姓名：</label>-->
<!--                                <input type="text" name="sendPerson"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件详细地址：</label>-->
<!--                                <input type="text" name="sendDetail"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件电话号码：</label>-->
<!--                                <input type="text" name="sendPhonenum"/>-->
<!--                            </li>-->
                            <li>
                                <label>收件数据：</label>
                                <input type="text" name="receiveText"/>
                            </li>
                            <li>
                                <label>退单申请：</label>
                                <select name="sign">
                                    <option value="">请选择</option>
                                    <option value="1">退单申请</option>
                                </select>
<!--                                <input type="text" name="receiveText"/>-->
                            </li>
<!--                            <li>-->
<!--                                <label>收件省：</label>-->
<!--                                <input type="text" name="receiveProvince"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件市：</label>-->
<!--                                <input type="text" name="receiveCity"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>收件区：</label>-->
<!--                                <input type="text" name="receiveCounty"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>收件街道：</label>-->
<!--                                <input type="text" name="receiveTown"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>收件姓名：</label>-->
<!--                                <input type="text" name="receivePerson"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>收件详细地址：</label>-->
<!--                                <input type="text" name="receiveDetail"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>寄件电话号码：</label>-->
<!--                                <input type="text" name="receivePhonenum"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                shiro:hasPermission="system:Information:add"-->
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                shiro:hasPermission="system:Information:edit"-->
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" >-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                shiro:hasPermission="system:Information:remove"-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" th:if="${loginUser} eq admin" >
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:Information:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
                &nbsp;&nbsp;&nbsp;<span style="font-size: 15px;float: right;display:block;width: 200px;height: 25px" id="transactionFee" th:text="'您的发货单价为:'+${spend}"></span>
                <span style="font-size: 15px;float: right;display:block;width: 200px;height: 25px" id="settlementFee" th:text="'您的账户余额为:'+${amount}"></span>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:Information:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:Information:remove')}]];
        var prefix = ctx + "system/Information";

        loginUser=[[${loginUser}]];
        console.log(loginUser)
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "【添加订单】",
                sortName: "createTime",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '订单id',
                    align: 'center',
                    // visible: false
                },
                {
                    field: 'sendText',
                    title: '寄件人数据',
                    align: 'center',
                },
                // {
                //     field: 'sendProvince',
                //     title: '寄件省'
                // },
                // {
                //     field: 'sendCity',
                //     title: '寄件市'
                // },
                // {
                //     field: 'sendCounty',
                //     title: '寄件区'
                // },
                // {
                //     field: 'sendTown',
                //     title: '寄件街道'
                // },
                // {
                //     field: 'sendPerson',
                //     title: '寄件姓名'
                // },
                // {
                //     field: 'sendDetail',
                //     title: '寄件详细地址'
                // },
                // {
                //     field: 'sendPhonenum',
                //     title: '寄件电话号码'
                // },
                {
                    field: 'receiveText',
                    title: '收件人数据',
                    align: 'center',
                },
                // {
                //     field: 'receiveProvince',
                //     title: '收件省'
                // },
                // {
                //     field: 'receiveCity',
                //     title: '寄件市'
                // },
                // {
                //     field: 'receiveCounty',
                //     title: '收件区'
                // },
                // {
                //     field: 'receiveTown',
                //     title: '收件街道'
                // },
                // {
                //     field: 'receivePerson',
                //     title: '收件姓名'
                // },
                // {
                //     field: 'receiveDetail',
                //     title: '收件详细地址'
                // },
                // {
                //     field: 'receivePhonenum',
                //     title: '寄件电话号码'
                // },
                    {
                        field: 'amount',
                        title: '金额',
                        align: 'center',
                    },
                    // {
                    //     field: 'loginName',
                    //     title: '登录名'
                    // },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        align: 'center',
                    },
                    {
                        field: 'state',
                        align: 'center',
                        title: '订单状态',
                        formatter:function (value,row,index) {

                            if(value==null)value='';
                            return '<span id="span_'+row.id +'">'+value+'</span>'

                        }
                    },
                    {
                        field: 'sign',
                        title: '标记',
                        visible: false
                    },
                    {
                        field: 'loginName',
                        title: '登录名称',
                        visible: false
                    },
                    {
                        field: 'number',
                        title: '订单号',
                        align: 'center',
                    },
                    {
                        field: 'name',
                        title: '姓名',
                        align: 'center',
                    },
                    {
                        field: 'phone',
                        title: '电话',
                        align: 'center',
                    },
                    {
                        field: 'code',
                        title: '对货码',
                        align: 'center',
                    },
                    {
                        field: 'rookieAccount',
                        title: '订单数据',
                        align: 'center',
                    },
                    {
                        field: 'fail',
                        title: '菜鸟下单状态',
                        align: 'center',
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.sign==0&&loginUser!="admin"&&row.state!="订单退款") actions.push('<a  id ="aa"class="btn btn-danger btn-xs" onclick="updateSign1(\'' + row.id + '\')"><i class="fa fa-edit"></i>退单</a> ');
                        if(row.sign==1) actions.push('<span STYLE="color: red">退单处理中</span>');
                        if (row.sign==1&&loginUser=="admin")actions.push('<a class="btn btn-success btn-xs" onclick="updateSign2(\'' + row.id + '\',\'' + row.loginName + '\')"><i class="fa fa-edit"></i>允许退款</a> ');
                        if (row.sign==1&&loginUser=="admin")actions.push('<a class="btn btn-danger btn-xs " onclick="updateSign3(\'' + row.id + '\')"><i class="fa fa-edit"></i>拒绝退款</a> ');
                        actions.push('&nbsp;');
                        if(row.sign==2) actions.push('<span STYLE="color: #00a65a">同意退单</span>');
                        if(row.sign==3) actions.push('<span STYLE="color: #00a65a">拒绝退单</span>');
                        actions.push('&nbsp;');
                        // ' + editFlag + '
                        if (loginUser=="admin")actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // ' + removeFlag + '
                        if (loginUser=="admin")actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if(loginUser=="admin"&&row.state!="订单退款")actions.push(' <select class="state" name="state" id="'+row.id+'" onchange="func(\'' + row.id + '\',\'' + row.loginName + '\')">\n'+
                            '             <option value="">请订单状态</option>\n' +
                            '             <option value="待处理" id="id1">待处理</option>\n' +
                            '             <option value="已完成" id="id2">已完成</option>\n' +
                            '             <option value="订单退款" id="id3">订单退款</option>\n' +
                            '          </select>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        //监听库房选择事件
        function func(id,loginName){
            // console.log(id)
            // var selectedId=$("#"+id+" option:selected").val();
            var selectedId=$("#"+id).val();
            console.log(selectedId)
            // console.log(selectedId)
            $("#span_"+id).html(selectedId)
            $.ajax({
                type:'Post',
                url:'/system/Information/updateState',
                dataType:'json',
                data:{id:id,state:selectedId},
                success:function (data){
                    $.form.reset()
                    if (selectedId=="订单退款"){
                        $.ajax({
                            type:'Post',
                            url:'/system/Information/amountAdd',
                            data:{loginUser:loginName,id:id},
                            dataType:'json',
                            success:function (data){
                            },
                            error:function (error){
                            }
                        })
                    }
                },
                error:function (error){
                }
            })
        }

        function updateSign1(id){
            $.modal.confirm("确定要退单吗？",function (){
                $.ajax({
                    type: 'Post',
                    url:'/system/Information/updateSign1',
                    data: {id:id},
                    dataType: 'json',
                    success:function (data){
                        $.form.reset()
                    },
                    error:function (error){
                    }
                })
            })
        }
        function updateSign2(id,loginName){
            // console.log(loginName)
            $.ajax({
                type: 'Post',
                url:'/system/Information/updateSign2',
                data: {id:id},
                dataType: 'json',
                success:function (data){
                    $.form.reset()
                    $.ajax({
                        type:'Post',
                        url:'/system/Information/amountAdd',
                        data:{loginUser:loginName},
                        dataType:'json',
                        success:function (data){
                        },
                        error:function (error){
                        }
                    })
                },
                error:function (error){
                }
            })
        }

        function updateSign3(id){
            $.ajax({
                type: 'Post',
                url:'/system/Information/updateSign3',
                data: {id:id},
                dataType: 'json',
                success:function (data){
                    $.form.reset()
                },
                error:function (error){
                }
            })

        }



    </script>
</body>
</html>